package com.ellricky.baselib.ui.clue

import androidx.recyclerview.widget.GridLayoutManager
import com.andr.common.ui.activity.BaseToolBarActivity
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.R
import com.ellricky.baselib.adapter.SimpleImageAdapter
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.VisitDetail
import com.ellricky.baselib.http.HttpUtils
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.NewECallback
import kotlinx.android.synthetic.main.activity_visit_detail.*
import kotlinx.android.synthetic.main.base_activity_track.tv_time
import java.util.*

class VisitDetailActivity : BaseToolBarActivity<Void, BasePresenter<Void>>() {

    private val id: String by lazy {
        intent.getStringExtra(BaseConstant.KEY_ID) ?: ""
    }

    private val adapterSimple :SimpleImageAdapter by lazy {
        SimpleImageAdapter()
    }

    override fun getContentLayout(): Int {
         return R.layout.activity_visit_detail
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = "回访记录"
        rvVisit.adapter = adapterSimple
        rvVisit.layoutManager = GridLayoutManager(this,3)

        fetchVisitDetail()
    }

    private fun fetchVisitDetail() {
        val url = EAppUtil.getApiHost()
        val paramMap: MutableMap<String, String> = HashMap()
        paramMap["action"] = getActions()
        paramMap["return_id"] = id
        paramMap["eid"] = LocalCacheUtil.getUid()

        HttpUtils.getInstance()
            .postFrom(url, paramMap, object : NewECallback<VisitDetail>(this) {
                override fun onSuccess(data: VisitDetail, msg: String) {
                    tv_time.text = "第${data.mr_number}次回访"
                    item_2.value = data.mr_return_time
                    item_3.value = data.mr_next_time
                    item_4.value = data.mr_desc
                    data.imgs?.also {
                        adapterSimple.refresh(it)
                    }
                }
            })
    }

    private fun getActions(): String {
        return when (LocalCacheUtil.getCardType()) {
            BaseConstant.CARD_PRESIDENT -> "headQueryReturnRemark"
            BaseConstant.CARD_TEACHER_MANAGER -> "gzaQueryReturnRemark"
            else -> "memberReturnList"
        }
    }
}